package com.yanqu.road.server.cmd.activity.pawnshop;

import com.yanqu.road.entity.activity.pawnshop.PawnshopItem;
import com.yanqu.road.pb.activity.PawnshopProto.PawnshopEventHockConfirmReqMsg;
import com.yanqu.road.server.cmd.base.AbstractCommand;
import com.yanqu.road.server.command.Cmd;
import com.yanqu.road.server.gameplayer.GamePlayer;
import com.yanqu.road.server.gameplayer.module.activity.pawnshop.PawnshopModule;
import com.yanqu.road.server.manger.activity.pawnshop.PawnshopMgr;
import com.yanqu.road.message.YanQuMessage;
import com.yanqu.road.server.protocol.GameErrorCode;
import com.yanqu.road.server.protocol.GameProtocol;

@Cmd(code = GameProtocol.S_PAWNSHOP_EVENT_HOCK_CONFIRM, desc = "请求典当事件确认")
public class PawnshopEventHockConfirmCmd extends AbstractCommand {

    private boolean isConfirm = false;// 是否确认
    private int goodsIdReward = 0;// 获得的货物ID
    private long coinCost = 0;// 花费的当铺币

    @Override
    public boolean parseData(YanQuMessage packet) throws Exception {
        PawnshopEventHockConfirmReqMsg reqMsg = PawnshopEventHockConfirmReqMsg.parseFrom(packet.getBytes());
        isConfirm = reqMsg.getIsConfirm();
        return true;
    }

    @Override
    public void execute(GamePlayer player, YanQuMessage packet) throws Exception {
        if (!PawnshopMgr.isActivityInTime()) {
            // 非活动时间内
            this.ret = GameErrorCode.E_ACTIVITY_OVER_TIME;
            return;
        }
        PawnshopModule psModule = player.getModule(PawnshopModule.class);
        if (!psModule.getUserPawnshop().isReception()) {
            // 顾客未接待过
            this.ret = GameErrorCode.E_PAWNSHOP_NOT_RECEPTION;
            return;
        }
        PawnshopItem itemJSON = psModule.getPawnshopItemJSON();
        if (itemJSON == null) {
            // 不存在的物件
            this.ret = GameErrorCode.E_PAWNSHOP_NOT_ITEM;
            return;
        }
        ret = player.getModule(PawnshopModule.class).addHockItem(isConfirm);

    }

    @Override
    public void sendData(GamePlayer player) {

    }
}
